<script setup lang="ts">
  import { onLaunch, onShow, onHide } from '@dcloudio/uni-app';
  import { useAppStore } from './store/modules/app';
  import { useTmpiniaStore } from './tmui/tool/lib/tmpinia';

  const { setResolvePrivacyAuthorization, setPrivacyPopupVisible, getAccountInfoSync } =
    useAppStore();

  const { setTmVuetifyTheme } = useTmpiniaStore();

  setTmVuetifyTheme('primary');

  getAccountInfoSync();

  /** 每次启动程序 清空文件缓存 */
  function removeSavedFile() {
    let fileSystemManager = wx.getFileSystemManager();
    fileSystemManager.readdir({
      dirPath: `${wx.env.USER_DATA_PATH}`,
      success: ({ files }) => {
        files.forEach((item) => {
          fileSystemManager.unlink({
            filePath: `${wx.env.USER_DATA_PATH}/${item}`,
          });
        });
      },
    });
  }

  onLaunch(() => {
    console.log('App Launch');
    // #ifdef MP-WEIXIN
    removeSavedFile();
    // #endif
  });
  onShow((res) => {
    // #ifdef MP
    if (wx.onNeedPrivacyAuthorization) {
      console.log('onNeedPrivacyAuthorization init');
      wx.onNeedPrivacyAuthorization((resolve) => {
        setResolvePrivacyAuthorization(resolve as any);
        setPrivacyPopupVisible(true);
        console.log('onNeedPrivacyAuthorization success');
      });
    }
    // #endif
    console.log('App Show');
  });
  onHide(() => {
    console.log('App Hide');
  });
</script>
<style lang="scss">
  /* #ifndef APP-NVUE */
  @import './tmui/scss/noNvue.css';
  /* #endif */
  @import './static/css/iconfont.css';
  // @import './static/css/ant-iconfont.css';
  // @import './styles/index.scss';
</style>
